package demo8;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class Person {
    private String name;
    private int age;

    public Person() {
        System.out.println("Person的构造器执行了");
    }

    public String getName() {
        return name;
    }

    @Value("张三")
    public void setName(String name) {
        System.out.println("Person的setName方法执行了");
        this.name = name;
    }

    @PostConstruct
    //添加此注解，方法执行就表示Spring已经实例化对象了
    public void init(){
        System.out.println("Person的init方法执行了");
    }

    @PreDestroy
    //销毁前会调用此方法
    public void destroy(){
        System.out.println("Person的destroy方法执行了");
    }

    public int getAge() {
        return age;
    }

    @Value("18")
    public void setAge(int age) {
        System.out.println("Person的setAge方法执行了");
        this.age = age;
    }
}
